<?php
require_once("../../config.inc.php");
require_once("../_inc/mix.func.php");
require_once("../_inc/html/funzHTML.php");
require_once("../_inc/mbUser.class.php");
require_once("../_inc/sdao/StructuredDataAccessObject.php");
if (!isset($objSDAO)) $objSDAO = new SDAO($aMetaConPar);
if(!isset($_REQUEST["uid"])){
	header("location:login.php?errMsg=0003");
	exit();
}
if(!isset($_REQUEST["pwd"])){
	header("location:login.php?errMsg=0002");
	exit();
}
$oUser = new mbUser();
$oUser->login($_REQUEST["uid"], $_REQUEST["pwd"]);
if($oUser->error == ""){
	session_start();
   $k=1;
   while(isset($_SESSION['polarismb'.$k])) {$k++;}
   define('USEROBJ','polarismb'.$k);
   define('XSN',"$k.1");
	$_SESSION[USEROBJ] = $oUser;
   // -- create new session record
	$oUser->uniqid = md5(uniqid(rand(), true));
	list($usec, $sec) = explode(" ", microtime());
	$tsNow = date('Y-m-d H:i:s',$sec).substr($usec,1,7); 
	$oUser->pageSequence = 1;
	$sSQL = "INSERT INTO session " .
			"(uniqid, time_in, id_user, session_id, sub_session, time_last, log_out) " .
			"VALUES('".$oUser->uniqid."', TIMESTAMP('$tsNow'), ".$oUser->id.", '".session_id()."',".XSN.",TIMESTAMP('$tsNow'),'N')";	
	$bRC = $objSDAO->query($sSQL,"insSess");
   //
   logRecord(100,"Log in ".$oUser->user.' - '.$oUser->name.' '.$oUser->surname);
	serverRedir("../data/area/dataAreaList.php?xsn=".XSN);
	exit();
}
logRecord(120,"Log in denied for ".$oUser->user);
header("location:login.php?errMsg=".$oUser->errno);
exit();



?>
